Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🍪 문제 이름
Resolve: 실패율
🍊 문제 정의
inputN: 전체 스테이지 수 (1 이상 500 이하)stages: 사용자가 현재 머물러 있는 스테이지 번호 배열 (1 이상 N+1 이하, N+1은 모든 스테이지를 클리어한 사용자)output예시
🍑 알고리즘 설계
Counter로 각 스테이지에 머물러 있는 사용자 수를 미리 집계.1번 스테이지부터 N번 스테이지까지 순회하면서, 현재 스테이지에 도달한 사용자 수(
total)로 실패율을 계산하고, 해당 스테이지에 머문 사용자 수를total에서 빼서 다음 스테이지의 도달자 수를 갱신.total이 0이면 실패율을 0으로 처리. 최종적으로 실패율 기준 내림차순으로 스테이지 번호를 정렬해 반환.🥝 최악 수행 시간 복잡도
O(n + N log N)(n = stages 길이, N = 스테이지 수)Counter생성에 O(n), 스테이지 순회에 O(N), 정렬에 O(N log N)이므로 전체 O(n + N log N)🍰 특이 사항 (Optional)
total을 매 스테이지마다 해당 스테이지 머문 인원만큼 줄여가며 다음 스테이지의 도달자 수를 구하는 부분에서, 이걸 빠뜨리면 분모가 계속 전체 사용자 수로 고정되어 오답이 나옴.